// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';
import { SidebarProvider } from "./web";
// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {

	const sidebarProvider = new SidebarProvider(context)
	
	context.subscriptions.push(
		vscode.commands.registerCommand('twy.explain', () => {
			vscode.commands.executeCommand('twy.sidebar.focus')
			const editor = vscode.window.activeTextEditor;
			if (editor) {
				const selection = editor.selection;
				const selectedCode = editor.document.getText(selection);
				setTimeout(()=>{
					sidebarProvider.postMessageToWebview(selectedCode)
				},2000)
			} else {
				vscode.window.showErrorMessage('No active editor found!');
			}

		  }),
		vscode.window.registerWebviewViewProvider('twy.sidebar', sidebarProvider),
	);

	
}

// This method is called when your extension is deactivated
export function deactivate() {}
